﻿using System;
using System.Windows;
using System.Reflection;
using System.Windows.Controls;

namespace Builderator.Firefly.Controls
{
    /// <summary>
    /// Interaction logic for IntegerControl.xaml
    /// </summary>
    public partial class IntegerControl : UserControl, IProperty
    {
        public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(Int32), typeof(IntegerControl));

        public new event PropertyChanged OnPropertyChanged;

        public int Value
        {
            get
            {
                return (int)this.GetValue(ValueProperty);
            }
            set
            {
                this.SetValue(ValueProperty, value);

                this.textTextBox.Text = value.ToString();

                if (this.OnPropertyChanged != null)
                    this.OnPropertyChanged(this.Property, value);
            }
        }

        public PropertyInfo Property
        {
            get;
            set;
        }
        private IntegerControl()
        {
            InitializeComponent();
        }

        public IntegerControl(PropertyInfo property)
            : this()
        {
            this.Property = property;
        }

        private void textTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.Value = Int32.Parse(this.textTextBox.Text);
        }
    }
}
